﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;
using System.Data;

public partial class Video_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThiVideo();
            Pager1.CurrentIndex = 1;
            binding(Pager1.CurrentIndex);                
            hienThiFirstVideo();   
        }
    }
    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        binding(currnetPageIndex-1);
    }
    private void HienThiVideo()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause="1=1 and trangthai = 1";
        TList<Video> TList_Video = DataRepository.VideoProvider.GetPaged(WhereClause, "Id DESC", 0, 3, out TotalRows);
        if (TList_Video.Count > 0)
        {
            String a = "http://img.youtube.com/vi/";
            String b = "/0.jpg";
            String c = "//www.youtube.com/embed/";
            for (int i = 0; i <= TList_Video.Count-1; i++)
            {
                strHTML += "<div style=\"border-color:#efefef; border-width:3px; border-style:solid; padding: 5px;border-bottom-width:1px; border-bottom-color: Black; border-bottom-style: solid\" onclick=\"doivideo('" + c + TList_Video[i].MaCode + "','" + TList_Video[i].TieuDe + "')\"><img width=\"112px\" src=\"" + a + TList_Video[i].MaCode + b + "\" /><div class=\"row\">";
                strHTML += "<p class=\"classdulich\">" + TList_Video[i].TieuDe + "</p><br />";
                //strHTML += "<p class=\"version\">" + TList_Video[i].DienGiai.ToString().Substring(0,50) + "</p></div></div><hr />"; 
                if (TList_Video[i].DienGiai.ToString().Length > 50)
                    strHTML += "<p class=\"version\" style=\"\">" + TList_Video[i].DienGiai.ToString().Substring(0, 50) + "</p></div></div>";      
                else
                    strHTML += "<p class=\"version\">" + TList_Video[i].DienGiai.ToString() + "</p></div></div>";      
            }
            litvideo.Text = strHTML;
        }

        
        
    }
    private void binding(int PageNo)
    {
        int TotalRows = 0;
        string WhereClause = "1=1";
        TList<Video> TList_Video = DataRepository.VideoProvider.GetPaged(WhereClause, "id DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
        
        dlVideo.DataSource = TList_Video;
        dlVideo.DataBind();

        Pager1.ItemCount = TotalRows;
        if (TotalRows <= Pager1.PageSize)
            Pager1.Visible = false;
        else
            Pager1.Visible = true;
    }
    private void hienThiFirstVideo()
    {
        string strHTML = "";
        string html = "";
        int TotalRows = 0;
        string WhereClause="1=1 and trangthai = 1";
        TList<Video> TList_Video = DataRepository.VideoProvider.GetPaged(WhereClause, "Id DESC", 0, 1, out TotalRows);
        if (TList_Video.Count > 0)
        {
            String a = "http://img.youtube.com/vi/";
            String b = "/0.jpg";
            String c = "//www.youtube.com/embed/";
            for (int i = 0; i <= TList_Video.Count-1; i++)
            {

                strHTML += "<iframe id=\"khungVideo\" width=\"98%\" height=\"80%\" src=\"" + c + TList_Video[i].MaCode + "\" frameborder=\"0\" allowfullscreen style=\"margin-left: 1%; margin-top: 1%;\"></iframe>";
                html += "<p id=\"tieuDe\" class=\"duoiViDeo\">" + TList_Video[i].TieuDe + "</p>";
            }
            firstVideo.Text = strHTML;
            tieuDeduoi.Text = html;
        }
        
    }
    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
   
}